﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CApStopZeroEnumerableUtils
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;


namespace DnProcessSimulateCommands.StopZero;

internal static class CApStopZeroEnumerableUtils
{
  public static bool IsDifferent<T>(this IEnumerable<T> destination, IEnumerable<T> source)
  {
    if (destination == source)
      return false;
    return destination == null || source == null || !new HashSet<T>(source).SetEquals(destination);
  }

  public static void ForEach<TFirst, TSecond>(
    this IEnumerable<TFirst> first,
    IEnumerable<TSecond> second,
    Action<TFirst, TSecond> action)
  {
    using (IEnumerator<TFirst> enumerator1 = first.GetEnumerator())
    {
      using (IEnumerator<TSecond> enumerator2 = second.GetEnumerator())
      {
        while (enumerator1.MoveNext() && enumerator2.MoveNext())
          action(enumerator1.Current, enumerator2.Current);
      }
    }
  }

  public static void ForEach<TFirst, TSecond, TThird>(
    this IEnumerable<TFirst> first,
    IEnumerable<TSecond> second,
    IEnumerable<TThird> third,
    Action<TFirst, TSecond, TThird> action)
  {
    using (IEnumerator<TFirst> enumerator1 = first.GetEnumerator())
    {
      using (IEnumerator<TSecond> enumerator2 = second.GetEnumerator())
      {
        using (IEnumerator<TThird> enumerator3 = third.GetEnumerator())
        {
          while (enumerator1.MoveNext() && enumerator2.MoveNext() && enumerator3.MoveNext())
            action(enumerator1.Current, enumerator2.Current, enumerator3.Current);
        }
      }
    }
  }

  public static IEnumerable<T> TakeUntil<T>(this IEnumerable<T> source, Func<T, bool> predicate)
  {
    foreach (T obj in source)
    {
      T item = obj;
      yield return item;
      if (predicate(item))
        item = default (T);
      else
        break;
    }
  }

  public static IEnumerable<T> SkipUntil<T>(this IEnumerable<T> source, Func<T, bool> predicate)
  {
    using (IEnumerator<T> enumerator = source.GetEnumerator())
    {
      do
        ;
      while (enumerator.MoveNext() && predicate(enumerator.Current));
      while (enumerator.MoveNext())
        yield return enumerator.Current;
    }
  }
}
